package com.atguigu.gmall.seckill.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.activity.SeckillGoods;
import com.atguigu.gmall.seckill.service.SeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: dongdong lau
 * @CreateTime: 2021/7/15 10:29
 * @Description: 秒杀微服务controller层
 */
@RestController
@RequestMapping(value = "/seckill")
public class SeckillController {

    @Autowired
    private SeckillService seckillService;

    /**
     * 根据时间查询时间所在时间段内所有秒杀商品
     * @param time
     * @return
     */
    @RequestMapping(value = "/findAll/{time}")
    public List<SeckillGoods> findAll(@PathVariable("time") String time){
        List<SeckillGoods> seckillGoods = seckillService.findAll(time);
        return seckillGoods;
    }

    /**
     * 根据时间和商品Id查询商品详情
     * @param time
     * @param id
     * @return
     */
    @RequestMapping(value = "/getSeckillGoods/{time}/{id}")
    public SeckillGoods getSeckillGoods(@PathVariable(value = "time") String time,
                                        @PathVariable(value = "id") String id){
        SeckillGoods seckillGoods = seckillService.getSeckillGoods(time, id);
        return seckillGoods;
    }
}
